package com.base.cn.platform.os.controller.mobile.user.center.account;

import com.base.cn.platform.os.common.MobileBaseController;
import com.base.cn.platform.os.service.manage.user.account.CusUserAccountHistoryService;
import com.base.cn.platform.os.service.manage.user.account.CusUserAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;


/**
 * 我的账户
 * @author ll
 * @date 2018/7/4 14:56
 */
@Controller
@RequestMapping("/mobile/uc/account")
public class MobileUserAccountController  extends MobileBaseController {
    @Autowired
    private CusUserAccountService cusUserAccountService;
    @Autowired
    private CusUserAccountHistoryService cusUserAccountHistoryService;
    /**
     * 我的账号
     * @param model
     * @return
     */
    @RequestMapping("/myAccount")
    public String ucMyAccount(HttpServletRequest request,Model model){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        Map<String,Object> userAccount =cusUserAccountService.userAccountInfo(userId,false);
        model.addAttribute("userAccount",userAccount);
        return resultPage("/user/center/account/u-account");
    }

    /**
     * 账户历史列表
     * @param request
     * @return
     */
    @RequestMapping("/ajax/queryUserAccountHistories")
    public String queryUserAccountHistories(Model model,
                                            @RequestBody Map<String,Object> params,
                                            HttpServletRequest request,
                                            @RequestParam(value = "currentPage",required = false,defaultValue = "1") Integer currentPage) {
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        params.put("userId",userId);
        Map<String,Object> dataMap = cusUserAccountHistoryService.userAccountHistoryListPage(params, currentPage,false);
        model.addAttribute("dataMap",dataMap);
        return resultPage("/user/center/account/u-ajax-account");
    }

}
